package it.tempogara.tgsender;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import it.tempogara.tgsender.R;

public class BrowseActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_browse);
		ListView lv = (ListView) findViewById(R.id.listView1);
		File f = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/TGSender/"+new SimpleDateFormat("ddMMyyyy").format(new Date()));
		if(f.exists()){
			String[] values = f.list();
			lv.setAdapter(new ArrayAdapter<String>(this, R.layout.row, values));
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.browse, menu);
		return true;
	}
	
	public void svuota(View v){
		File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/TGSender/"+new SimpleDateFormat("ddMMyyyy").format(new Date()));
		if(dir.exists()){
			String[] files = dir.list();
			for(int i=0;i<files.length;i++)
				new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/TGSender/"+new SimpleDateFormat("ddMMyyyy").format(new Date())+"/"+files[i]).delete();
		}
		ListView lv = (ListView) findViewById(R.id.listView1);
		lv.setAdapter(new ArrayAdapter<String>(this, R.layout.row, dir.list()));
	}
	
	public void indietro(View v){
		finish();
	}

}
